package components.custom
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.controls.listClasses.MXItemRenderer;
	
	import spark.layouts.HorizontalLayout;
	
	import components.base.BaseLabel;
	
	import interfaces.IDispose;
	
	public class MenuSublistItemRenderer extends MXItemRenderer implements IDispose
	{
		public static const MENU_ITEM_CLICK:String = "menuItemClick";
		private var lbtn:BaseLabel = new BaseLabel();
		
		public function MenuSublistItemRenderer()
		{
			super();
			height = 20;
			percentWidth = 100;
			var hl:HorizontalLayout = new HorizontalLayout();
			hl.paddingLeft = 20;
			hl.verticalAlign = "middle";
			layout = hl;
			
			lbtn.percentHeight = 100;
			lbtn.buttonMode = true;
			lbtn.mouseChildren = false; 
			lbtn.setStyle("fontSize", 12);
			lbtn.setStyle("fontWeight", "bold");
			lbtn.setStyle("verticalAlign", "middle");
			lbtn.setStyle("color", "0x636363");
			addElement(lbtn);
			
			addEventListener(MouseEvent.CLICK, mouseEventHandler);
			addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
			addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
		}
		
		public function dispose():void
		{
			removeEventListener(MouseEvent.CLICK, mouseEventHandler);
			removeEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
			removeEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
		}
		
		override public function set data(value:Object):void
		{
			super.data = value;
			setLabel(value as XML);
		}
		
		/**
		 * 鼠标点击链接按钮
		 * @param p_evt
		 * 
		 */		
		private function mouseOverHandler(p_evt:MouseEvent):void
		{
			if(!lbtn)return;
			lbtn.setStyle("color", "0x2071AD");
		}
		/**
		 * 鼠标点击链接按钮
		 * @param p_evt
		 * 
		 */		
		private function mouseOutHandler(p_evt:MouseEvent):void
		{
			if(!lbtn)return;
			lbtn.setStyle("color", "0x636363");
		}
		
		/**
		 * 创建点击链接到Module的linkButton
		 * @param p_xml
		 * @return 
		 * 
		 */		
		private function setLabel(p_xml:XML):void
		{
			lbtn.data = p_xml;
			lbtn.locale = p_xml.@label;
		}
		
		/**
		 * 鼠标点击链接按钮
		 * @param p_evt
		 * 
		 */		
		private function mouseEventHandler(p_evt:MouseEvent):void
		{
			dispatchEvent(new Event(MENU_ITEM_CLICK, true));
		}
	}
}